@extends ("main")
@section ('title')
New Place
@endsection
@section ('content')
<script type="text/javascript">
	function successFunction2(position) {
	    var lat = position.coords.latitude;
	    var lng = position.coords.longitude;
	    $('#longitude').val(lng);
	    $('#latitude').val(lat);
	}
	

	function disableDom(){
		var countryDom = $('#country');
		var cityDom = $('#city');
		var districtDom = $('#district');
		var townDom = $('#town');
		var streetDom = $('#street');

		if(countryDom.val()==0){
			cityDom.val(0);
			cityDom.prop('disabled', true);		
		}
		if(cityDom.val()==0){
			districtDom.val(0);
			districtDom.prop('disabled', true);		
		}
		if(districtDom.val()==0){
			townDom.val(0);
			townDom.prop('disabled', true);		
		}
		if(townDom.val()==0){
			streetDom.val(0);
			streetDom.prop('disabled', true);		
		}

	}
</script>
{{ Form::open(array('route' => 'place.insert','id' => 'form_login', 'method' => 'post')) }}
	{{ $errors->first('username') }}
	{{ $errors->first('password') }}
	{{ Form::text('place_name', Input::old('place_name'),  array('placeholder'=>'Tên địa điểm'))  }}
	<br />
	{{ Form::textarea('place_description', Input::old('place_description'),  array('placeholder'=>'Mô tả địa điểm'))  }}
	<br />
	{{ Form::text('hotline', Input::old('hotline'),  array('placeholder'=>'Hotline'))  }}
	<br />
	{{ Form::text('tel_no', Input::old('tel_no'),  array('placeholder'=>'Số điện thoại'))  }}
	<br />
	{{ Form::text('website', Input::old('website'),  array('placeholder'=>'Trang chủ'))  }}
	<br />
	{{ Form::email('email', Input::old('email'),  array('placeholder'=>'email'))  }}
	<br />
	<label>địa chỉ đầy đủ: </label><span id='fullAddress'>aaaaaaaa</span>
	<br />
	{{ Form::text('country', Input::old('country'),  array('placeholder'=>'country', 'class'=>'typeahead', 'id' => 'country'))  }}
	{{Form::select('city', array('0' => 'Thành phố'), '0',array('id' => 'city', 'disabled' => ''))}}
	{{Form::select('district', array('0' => 'Quận'), '0',array('id' => 'district', 'disabled' => ''))}}
	{{Form::select('town', array('0' => 'Phường'), '0',array('id' => 'town', 'disabled' => ''))}}
	{{Form::select('street', array('0' => 'Đường'), '0',array('id' => 'street', 'disabled' => ''))}}
	<br>
	{{ Form::text('address', Input::old('address'),  array('placeholder'=>'Số nhà, ngõ cụ thể'))  }}
	<br />
	{{ Form::textarea('description', Input::old('description'),  array('placeholder'=>'Mô tả chi tiết'))  }}
	<br />
	{{ Form::text('open_time', Input::old('open_time'),  array('placeholder'=>'Giờ mở cửa'))  }}
	{{ Form::text('close_time', Input::old('close_time'),  array('placeholder'=>'Giờ đóng cửa'))  }}
	<br />
	{{ Form::hidden('longitude', 0, array('id' => 'longitude'))  }}
	{{ Form::hidden('latitude', 0, array('id' => 'latitude'))  }}
	{{ Form::submit('Thêm mới',array('class' => 'btn btn_login' )); }}
{{ Form::close() }}

<script type="text/javascript">
	$(document).ready(function() {
		getLocation(successFunction2);

		var countries = new Bloodhound({
			name: 'countries',
			remote: "{{URL::to('address/country')}}/%QUERY",
			datumTokenizer: function(d) {
				return Bloodhound.tokenizers.whitespace(d.country_name);
			},
			queryTokenizer: Bloodhound.tokenizers.whitespace
		});
		countries.initialize(true);
		
		$('#country.typeahead').typeahead({
			hint: true,
			highlight: true,
			minLength: 1
		},
		{
		name: 'countries',
		displayKey: 'country_name',
		// `ttAdapter` wraps the suggestion engine in an adapter that
		// is compatible with the typeahead jQuery plugin
		source: countries.ttAdapter()
		});
	});
</script>
@endsection

